﻿using System;
using System.Collections.Generic;
using Rabbit.Logic;
using RabbitShop.Code;

namespace RabbitShop.UI
{
    public partial class UserAddress : System.Web.UI.Page
    {
        protected string uid = string.Empty;
        protected List<Address> list;
        protected string aid = string.Empty;
        protected Address address = new Address();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies[Constant.CookieName] != null)
            {
                string id = Request.Cookies[Constant.CookieName].Values[Constant.CookieUid];
                if (string.IsNullOrEmpty(id)) Response.Redirect("UserLogon.aspx");
                uid = id;

                Customer customer = RabbitUse.GetCustomerById(Db.Store, uid);
                list = customer.AddressList;
                myRepeater.DataSource = list;
                myRepeater.DataBind();


                aid = Request["aid"];
                if (string.IsNullOrEmpty(aid)) return;
                int addressId;
                if (int.TryParse(aid, out addressId))
                {
                    if (list.Count <= addressId) return;
                    address = list[addressId];
                }
            }
            else
            {
                Response.Redirect("UserLogon.aspx");
            }
        }
    }
}